//节流函数
function throttle(func,delay=100){
    let lastTime=0;
    return function(...args){
        const now=Date.now();
        if(now-lastTime>=delay){
            func.apply(this,args);
            lastTime=now;
        }
    }
}

    const sidebar = document.getElementById('aside');
    const targetElement = document.getElementById('asideFoot');
    const footElement=document.getElementById('asideExtraFoot');
    const sideElement1=document.getElementById('asideImg');
    const sideElement2=document.getElementById('sec-middle');


    

 // 元素存在性检查
    if (!targetElement) {
        console.error('未找到id为"asideFoot"的元素');
    } else {
        const targetOffset = targetElement.offsetTop;
        let isFixed = false; // 跟踪固定状态

        // 滚动处理函数
        function handleScroll() {
            const currentScrollY = window.scrollY || document.documentElement.scrollTop;
            targetHeight=targetOffset-100;
            
            // 根据滚动位置应用或恢复固定状态
            if (currentScrollY >= targetHeight && !isFixed) {
                footElement.style.display='block';
                sidebar.classList.add('fixed');
                sideElement1.style.display = 'none';
                sideElement2.style.display = 'none';
                isFixed = true;
                console.log("范围外")
            } else if (currentScrollY < targetHeight && isFixed) {
                footElement.style.display='none'
                sidebar.classList.remove('fixed');
               sideElement1.style.display = 'block';
               sideElement2.style.display = 'block';
                isFixed = false;
                console.log("范围内")
            }
        }

        // 使用节流处理滚动事件，提高性能
        const throttledScrollHandler = throttle(handleScroll);
        
        // 添加滚动事件监听
        window.addEventListener('scroll', throttledScrollHandler);
        
        // 初始检查
        handleScroll();
    }